package com.wooboo.server.ext.action.traffic;


import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.SortedMap;
import java.util.TreeMap;

import com.wooboo.server.ext.ActionBase;
import com.wooboo.server.ext.ApiError;
import com.wooboo.server.ext.Result;
import com.wooboo.server.ext.data.PhoneTrafficGift;
import com.wooboo.server.ext.data.SysLogger;
import com.wooboo.server.ext.data.Traffic;
import com.wooboo.server.ext.data.TrafficGift;
import com.wooboo.server.ext.data.UserFinance;
import com.wooboo.server.ext.service.DbService;
import com.wooboo.server.ext.util.DateUtil;
import com.wooboo.server.ext.util.HttpClientUtils;
import com.wooboo.server.ext.util.NumberUtil;
import com.wooboo.server.ext.util.Parameters;
import com.wooboo.server.ext.util.StringUtil;

import net.sf.json.JSONObject;


/**
 * @author www.wooboo.com.cn
 * 流量申请领取回调。
 */
public class Applynotify extends ActionBase{
	public String portalType,portalID,transactionID,method,sequence,company_code;
	
	public String msisdn;//手机号
	public String product_id;//电话
	public String oper_time;//邮件
	public String result;
	public String resultDesc;
	public String sign;
	
	SortedMap<String, String> map =  new TreeMap<String, String>();
	
	public Applynotify(){
		 needCheckAuth =false;
	}
	
	@Override
	public void initParameters(Parameters params) throws ApiError {
		map.put("portalType",params.getFieldValue("portalType")); 
		map.put("portalID",params.getFieldValue("portalID")); 
		map.put("transactionID",params.getFieldValue("transactionID")); 
		map.put("method",params.getFieldValue("method")); 
		map.put("sequence",params.getFieldValue("sequence")); 
		map.put("company_code",params.getFieldValue("company_code")); 
		map.put("msisdn",params.getFieldValue("msisdn")); 
		map.put("product_id",params.getFieldValue("product_id")); 
		map.put("oper_time",params.getFieldValue("oper_time")); 
		map.put("result",params.getFieldValue("result")); 
		map.put("resultDesc",params.getFieldValue("resultDesc")); 
		//map.put("sign",params.getFieldValue("sign")); 
		String sign = params.getFieldValue("sign");
		
		String psign = Traffic.sign(map);
		
		if(!StringUtil.equals(sign, psign)){
			throw ApiError.Type.INVALID_PARAM.toException("签名错误！");
		}
	
		
	}
	
	@Override
	public Result invokeService() throws ApiError {
		Result result = new Result();
		DbService dbService = new DbService();
		
		
		String resultData = map.get("result");
		
		
		
		if("0".equals(resultData)){
			PhoneTrafficGift tg = dbService.findPhoneTrafficGiftBySequence(map.get("sequence"));
			if(null!=tg){
				
			}
		}else{
			
		}
		
		
		
	    return result;
	}
	
}
